/*
    M=m1 ∗ m2 ∗ ... ∗ mk
    Mi = M / mi
    x≡(a1 * M1 * inv_M1 + a2 * M2 * inv_M2 + ... + ak * Mk * inv_Mk) mod M
    中国剩余定理要求各个m互质
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 20;

ll n;
ll mods[N], r[N];

ll exgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) { x = 1, y = 0; return a; };
    ll g = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
}

ll inv(ll a, ll m)
{
    ll x, y;
    ll g = exgcd(a, m, x, y);
    return (x % m + m) % m;
}

int main()
{
    ll M = 1;
    cin >> n;
    for (ll i = 1;i <= n;i++) {
        cin >> mods[i] >> r[i];
        M = M * mods[i]; 
    }
    ll ans = 0;
    for (ll i = 1;i <= n;i++) {
        ll Mi = M / mods[i], inv_Mi = inv(Mi, mods[i]);
        ans = (ans + r[i] * Mi * inv_Mi % M + M) % M;
    }
    cout << ans;
}